import type React from 'react';
import { createStore } from 'heo';

export interface TabPageTodo {
  id: string;
  location: Location;
  jump: (path: string) => Promise<void>;
  push: (path: string) => Promise<void>;
  replace: (path: string) => Promise<void>;
  setTitle: (title: string, extra?: { icon?: React.ReactElement | string }) => void;
  addOnClose: (fn: () => Promise<boolean>) => void;
}

export interface AppStoreParams {
  ws?: WebSocket;
  tabPageTodo?: TabPageTodo;
}

export default createStore((params?: AppStoreParams) => {
  return {
    // iframe 模式中默认从 window 上获取
    // eslint-disable-next-line no-underscore-dangle
    tabPageTodo: window.__navTitle__?.tabPageTodo,
    ...params,
  };
});
